package org.yxj.customlibrary.v;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;


import org.yxj.customlibrary.R;
import org.yxj.customlibrary.util.Utils;

/**
 * 添加定制文字头
 *
 * @author yxj on 2022/8/3
 */
public class AddCustomTextHeadView extends LinearLayout implements View.OnClickListener {

    public View view ;
    public AddCustomTextHeadView(@NonNull Context context) {
        this(context,null);
    }

    public AddCustomTextHeadView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public AddCustomTextHeadView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        if (Build.VERSION.SDK_INT>=19){
            setPadding(0, Utils.getStatusBarHeight(context),0,0);
        }
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM);
        gradientDrawable.setColors(new int[]{
                Color.parseColor("#CC000000"),
                Color.TRANSPARENT
        });
        setBackground(gradientDrawable);
        addView(view = LayoutInflater.from(context).inflate(R.layout.add_custom_text_head_layout,this,false));


        TextView btn_finish = view.findViewById(R.id.btn_finish);
        GradientDrawable gradientDrawable1 = new GradientDrawable();
        gradientDrawable1.setCornerRadius(20);
        gradientDrawable1.setColor(Color.GREEN);
        btn_finish.setBackground(gradientDrawable1);


        view.findViewById(R.id.btn_cancel).setOnClickListener(this);
        view.findViewById(R.id.btn_finish).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_cancel) {
            if (addCustomTextHeadListener != null)
                addCustomTextHeadListener.onCancel();
        } else if (id == R.id.btn_finish) {
            if (addCustomTextHeadListener != null)
                addCustomTextHeadListener.onFinish();
        }
    }

    private AddCustomTextHeadListener addCustomTextHeadListener ;

    public void setAddCustomTextHeadListener(AddCustomTextHeadListener addCustomTextHeadListener) {
        this.addCustomTextHeadListener = addCustomTextHeadListener;
    }

    public interface AddCustomTextHeadListener{
        void onCancel();
        void onFinish();
    }
}
